/***************************************************************************
 *   Copyright (C) 2007 by gaojian   *
 *   gaojian2008cnn@126.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "settings.h"

#include <kapp.h>
#include <kconfig.h>

Settings::Settings()
{
}


Settings::~Settings()
{
}

void Settings::load()
{
	
	KConfig *config = kapp->config();
	
	// read Connection options
	config->setGroup("Connection");
	b_netcomOrTelecom = config->readBoolEntry("netcomOrTelecom", DEF_NETCOMORTELECOM);
	//read User options
	config->setGroup("user");
	username = config->readEntry("username", i18n("username"));
	userpassword = config->readEntry("userpassword", i18n("password"));
	//读取查词历史
	config->setGroup("History");
	histTextHistory = config->readListEntry("comboHistory");
	//读取是否开启了取词
	config->setGroup("iffetchWord");
	b_fetchWord= config->readBoolEntry("fetchWord", DEF_FETCHWORD);
	//读取是否开启修饰键
	config->setGroup("fetchWordKey");
	b_needModifier = config->readBoolEntry( "NeedModifier", DEF_NEEDMODIFIER );
	controlKey = config->readEntry("ModifierKey", i18n("Winkey"));
	if (  "Winkey" ==controlKey) buttonInt = 2048;
	else if( "Control" ==controlKey  ) buttonInt = 512;
	else if( "Alt" ==  controlKey) buttonInt = 1024;
	else if ( "Shift"==controlKey  )buttonInt = 256;

  config->sync();
}

void Settings::save()
{

	KConfig *config = kapp->config();
	qDebug("1234");
	
	// write connection options
	config->setGroup("Connection");
	config->writeEntry("netcomOrTelecom", b_netcomOrTelecom);
	//write User options
	config->setGroup("user");
	config->writeEntry("username", username);
	config->writeEntry("userpassword", userpassword);
	//写入查词历史
	config->setGroup("History");
	config->writeEntry("comboHistory",histTextHistory);
	//写入是否取词
	config->setGroup("iffetchWord");
	config->writeEntry("fetchWord", b_fetchWord);
	//写入是否开启修饰键
	config->setGroup("fetchWordKey");
	config->writeEntry( "NeedModifier",  b_needModifier);
	config->writeEntry("ModifierKey", controlKey);
	config->sync();

}




